﻿using System;
using System.Collections.Generic;
using System.Linq;
using TuxedoLib;
using SpaceSquirrel.SpecialLevelStuff;

namespace SpaceSquirrel
{
	public abstract class SpecialLevel
	{
		protected PlayScene scene;
		protected Context context;
		protected Tile[][] tiles;

		public bool HasUpdate { get; protected set; }
		public bool HasPostInit { get; protected set; }
		public bool HasDoorTrigger { get; protected set; }
		public bool HasRender { get; protected set; }

		public int lavaLevel = 0;
		public bool shakeScreen = false;
		public bool freeze = false;

		public SpecialLevel(PlayScene scene)
		{
			this.scene = scene;
			this.context = scene.Context;
			this.tiles = scene.Tiles;

			this.HasUpdate = false;
			this.HasPostInit = false;
			this.HasDoorTrigger = false;
			this.HasRender = false;
		}

		public virtual string DoorTrigger(string doorId)
		{
			return doorId;
		}

		public virtual void Update()
		{
			// override
		}

		public virtual void PostInit()
		{
			// override
		}

		public virtual void Render(Image screen, int offsetX, int offsetY, int renderCounter)
		{
			// override
		}

		private static SpecialLevel[] MakeList(params SpecialLevel[] stuff)
		{
			return stuff;
		}
		private static readonly SpecialLevel[] NO_SPECIAL_STUFF = new SpecialLevel[0];

		public static SpecialLevel[] GetSpecialLevelStuff(string id, PlayScene scene)
		{
			switch (id)
			{
				case "main": return MakeList(new BalloonPopping(scene, "water1"), new BalloonPopping(scene, "water2"), new BalloonPopping(scene, "lava1"));
				case "ship_1": return MakeList(new ShipTransmission(scene));
				case "grav_core": return MakeList(new GravityCorePlacement(scene));
				case "grav_ascent": return MakeList(new GravityAscentExit(scene));
				case "volcano_1_core": return MakeList(new VolcanoCoreActivation(scene, 1));
				case "volcano_2_core": return MakeList(new VolcanoCoreActivation(scene, 2));
				case "volcano_3_core": return MakeList(new VolcanoCoreActivation(scene, 3));
				case "balloon_2_overland": return MakeList(new BalloonPopping(scene, "water2"));
				case "balloon_3_overland": return MakeList(new BalloonPopping(scene, "water3"));
				case "bike_level": return MakeList(new BikeLevelStuff(scene));
				case "volcano_2_overland": return MakeList(new BalloonPopping(scene, "lava2"));
				case "volcano_3_overland": return MakeList(new BalloonPopping(scene, "lava3"));
				case "birdfeeder": return MakeList(new BirdFeeder(scene));
				default: return NO_SPECIAL_STUFF;
			}
		}
	}
}
